<%--
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
--%>
<%@ include file="/taglibs.jsp" %>
<c:set var="title" value="Edit Profile" scope="request"/>
<s:layout-render name="/layout/normal.jsp">
  <s:layout-component name="bodyElement">
    <body onload="$('password').value = ''">
  </s:layout-component>
  <s:layout-component name="body">
  <c:if test="${actionBean.authenticator.passwordManager}">
    <script type="text/javascript">
      function showPasswordField() {
        Element.show($('changeFields'));
        Element.hide($('changeLink'));
        $('password').focus();
      }
    </script>
  </c:if>
    <s:form beanclass="org.xptracker.web.ProfileActionBean">
      <table>
        <tbody id="mainInfo">
          <tr>
            <td class="form-label">Username:</td>
            <td>${actionBean.user.username}</td>
          </tr>
          <tr>
            <td class="form-label">Full Name:</td>
            <td><s:text name="user.fullName" size="30"/></td>
          </tr>
          <tr>
            <td class="form-label">Title:</td>
            <td><s:text name="user.title" size="30"/></td>
          </tr>
          <tr>
            <td class="form-label">Email Address:</td>
            <td><s:text name="user.email" size="30"/></td>
          </tr>
          <tr>
            <td class="form-label">Phone Number:</td>
            <td><s:text name="user.phoneNumber" size="30"/></td>
          </tr>
          <tr>
            <td class="form-label">Email Me When I Change a Story:</td>
            <td><s:checkbox name="user.emailMeMyChanges"/></td>
          </tr>
          <tr>
            <td class="form-label">Max Stories on Front Page:</td>
            <td><s:text name="user.blogEntryLimit" size="5"/></td>
          </tr>
        </tbody>
        <tbody id="queues">
          <tr>
            <td class="form-label">Queues:</td>
            <td>
              <table class="data">
                <thead>
                  <tr>
                    <th>Queue</th>
                    <th>Dashboard?</th>
                    <th>Email?</th>
                  </tr>
                </thead>
                <tbody>
                  <c:forEach items="${actionBean.queues}" var="queue">
                    <tr>
                      <td>${queue.name}</td>
                      <td>
                        <input type="checkbox" name="queuePresent" value="${queue.id}"
                           <c:if test="${xp:contains(user.queues, queue)}">checked="true"</c:if>/>
                      </td>
                      <td>
                        <input type="checkbox" name="queueEmail" value="${queue.id}"
                           <c:if test="${xp:contains(queue.trackers, user)}">checked="true"</c:if>/>
                      </td>
                    </tr>
                  </c:forEach>
                </tbody>
              </table>
            </td>
          </tr>
        </tbody>
        <tbody id="savedQueries">
          <tr>
            <td class="form-label">Queries:</td>
            <td>
              <div>
              <c:forEach items="${xp:sort(user.queries, 'name')}" var="query">
                <span style="float:right">
                [<s:link beanclass="org.xptracker.web.ProfileActionBean" onclick="return confirm('Really delete this query?')">
                  Delete
                  <s:param name="DeleteQuery" value="1"/>
                  <s:param name="queryId" value="${query.id}"/>
                </s:link>]
                </span>
                <input type="checkbox" name="queryPresent" value="${query.name}"
                    <c:if test="${xp:contains(user.homepageQueries, query.name)}">checked="true"</c:if>/> ${query.name}
                <br/>
              </c:forEach>
                </div>
            </td>
          </tr>
        </tbody>
        <tbody id="timelines">
          <tr>
            <td class="form-label">Timelines:</td>
            <td>
              <c:forEach items="${actionBean.timelines}" var="timeline">
                <input type="checkbox" name="timelinePresent" value="${timeline.id}"
                       <c:if test="${xp:contains(user.timelines, timeline)}">checked="true"</c:if>/> ${timeline.name}<br/>
              </c:forEach>
            </td>
          </tr>
        </tbody>
        <c:if test="${actionBean.authenticator.passwordManager}">
          <tbody id="changeLink">
            <tr>
              <td/>
              <td><a style="font-size:0.8em;" href="#"
                     onclick="showPasswordField()">
                Change Password...</a></td>
            </tr>
          </tbody>
          <tbody id="changeFields" style="display:none">
            <tr>
              <td colspan="2"><hr/></td>
            </tr>
            <tr>
              <td class="form-label">New Password:</td>
              <td><s:password id="password" name="_password"/></td>
            </tr>
            <tr>
              <td class="form-label">Confirm: </td>
              <td><s:password name="_confirm"/></td>
            </tr>
          </tbody>
        </c:if>
        <tbody>
          <tr>
            <td/><td><s:submit name="Update" value="Save"/></td>
          </tr>
        </tbody>
      </table>
      <c:if test="${actionBean.authenticator.passwordManager}">
        <s:errors field="_confirm">
          <s:errors-header><script type="text/javascript">showPasswordField()</script></s:errors-header>
          <span style="display:none"><s:individual-error/></span>
          <s:errors-footer></s:errors-footer>
        </s:errors>
      </c:if>
    </s:form>
  </s:layout-component>
</s:layout-render>